package search_handler

import (
	"peilian-api/app/global/bind"
	"peilian-api/app/global/databases/tables"
	"peilian-api/app/global/errors"
	"peilian-api/app/model"
	"peilian-api/app/services/search_service"
	"peilian-api/utils/format"

	"github.com/gin-gonic/gin"
)

func SearchSchool(ctx *gin.Context) {
	var srs model.SchoolRedisSearch
	if err := bind.ShouldBinding(ctx, &srs); err != nil {
		format.NewResponseJson(ctx).Err(errors.PublicErrorCode, errors.ParamBindError)
		return
	}
	out, _ := new(search_service.RedisSearch).GetSchool(ctx, srs)
	format.NewResponseJson(ctx).SuccessObj(out)
}

func SearchMysqlSchool(ctx *gin.Context) {
	var srs model.SchoolMysqlSearch
	if err := bind.ShouldBinding(ctx, &srs); err != nil {
		format.NewResponseJson(ctx).Err(errors.PublicErrorCode, errors.ParamBindError)
		return
	}
	out := new(tables.School).GetSchoolByQuery(srs.Query)
	format.NewResponseJson(ctx).SuccessObj(out)
}
